#include "../source/vlib.h"
#include <stdio.h>

static void test_create(void)
{
	deque_t deque = deque(int, 6);
	_deque(deque);
}

static void test_push_pop(void)
{
	deque_t deque = deque(int, 6);
	int data;
	
	for (int i = 0; i < 3; i++)
	{
		deque_push_front(deque, &i);
		deque_push_back(deque, &i);
	}
	
	for (int i = 0; i < 6; i++)
	{
		if (deque_pop_front(deque, &data)) printf("pop %d\r\n", data);
	}
	
	_deque(deque);
}

static void test_at(void)
{
	deque_t deque = deque(int, 6);
	
	for (int i = 0; i < 6; i++)
	{
		deque_push_back(deque, &i);
	}
	
	for (int i = 0; i < 6; i++)
	{
		printf("deque[%d] = %d\r\n", i, deque_at(deque, int, i));
	}
	
	_deque(deque);
}

static void test_insert(void)
{
	deque_t deque = deque(int, 6);
	
	for (int i = 0; i < 4; i++)
	{
		deque_push_back(deque, &i);
	}
	deque_insert(deque, 1, la(int, 1024), DEQUE_ORGIN_FRONT);
	
	for (int i = 0; i < deque_size(deque); i++)
	{
		printf("deque[%d] = %d\r\n", i, deque_at(deque, int, i));
	}
	
	_deque(deque);
}

static void test_erase(void)
{
	deque_t deque = deque(int, 6);
	
	for (int i = 0; i < 4; i++)
	{
		deque_push_back(deque, &i);
	}
	deque_erase(deque, 1, 2, DEQUE_ORGIN_FRONT);
	
	for (int i = 0; i < deque_size(deque); i++)
	{
		printf("deque[%d] = %d\r\n", i, deque_at(deque, int, i));
	}
	
	_deque(deque);
}

static void test_capacity(void)
{
	deque_t deque = deque(int, 6);
	
	for (int i = 0; i < 4; i++)
	{
		deque_push_back(deque, &i);
	}
	
	printf("capacity = %d\r\n", deque_capacity(deque));
	for (int i = 0; i < deque_size(deque); i++)
	{
		printf("deque[%d] = %d\r\n", i, deque_at(deque, int, i));
	}
	
	printf("-------------------\r\n");
	
	deque_alter_capacity(deque, 8);
	printf("capacity = %d\r\n", deque_capacity(deque));
	
	deque_alter_capacity(deque, 3);
	printf("capacity = %d\r\n", deque_capacity(deque));
	
	for (int i = 0; i < deque_size(deque); i++)
	{
		printf("deque[%d] = %d\r\n", i, deque_at(deque, int, i));
	}
	
	_deque(deque);
}

static void test_mode(void)
{
	deque_t deque = deque(int, 4);
	
	for (int i = 0; i < 4; i++)
	{
		deque_push_back(deque, &i);
	}
	
	for (int i = 0; i < deque_size(deque); i++)
	{
		printf("deque[%d] = %d\r\n", i, deque_at(deque, int, i));
	}
	
	printf("push result: %d\r\n", deque_push_back(deque, la(int, 100)));
	printf("push result: %d\r\n", deque_push_back(deque, la(int, 1000)));
	
	deque_mode(deque, DEQUE_MODE_OVERWRITE, DEQUE_SET_MODE);
	
	printf("push result: %d\r\n", deque_push_back(deque, la(int, 100)));
	printf("push result: %d\r\n", deque_push_back(deque, la(int, 1000)));
	
	for (int i = 0; i < deque_size(deque); i++)
	{
		printf("deque[%d] = %d\r\n", i, deque_at(deque, int, i));
	}
	
	_deque(deque);
}

static void test_init(void)
{
	DEQUE Q;
	int array[10];

	deque_init(&Q, array, sizeof(int), sizeof(array)/sizeof(array[0]));
	deque_deinit(&Q);
}

void test_deque(void)
{
	// test_create();
	test_push_pop();
	// test_at();
	// test_insert();
	// test_erase();
	// test_capacity();
	// test_mode();
	// test_init();
}